package microservicedemo.bookclient.controller;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import microservicedemo.bookclient.Client.BookServiceClient;
import microservicedemo.bookclient.model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@AllArgsConstructor
@Slf4j
@RestController
public class BookServiceClientController {

    private final BookServiceClient bookServiceClient;

    @PostMapping("/addBook")
    public boolean addBook(@RequestBody Book book){
        log.info("in client ------------addBook");
        return bookServiceClient.addBook(book);
    }

    @PostMapping("/delBook")
    public boolean delBook(@RequestBody Book book){
        log.info("in client ------------delBook");
        return bookServiceClient.delBook(book);
    }

    @PutMapping("/editBook")
    public boolean editBook(@RequestBody Book book){
        log.info("in client ------------editBook");
        return bookServiceClient.editBook(book);
    }

    @GetMapping("/getByTitle")
    public Book getByTitle(@RequestParam(value = "title") String title){
        log.info("in client ------------getByTitle");
        return bookServiceClient.getByTitle(title);
    }

    @GetMapping("/getByAuthor")
    public Book getByAuthor(@RequestParam(value = "author") String author){
        log.info("in client ------------getByAuthor");
        return bookServiceClient.getByAuthor(author);
    }
}
